package Week4;

import java.util.ArrayList;
import java.util.Iterator;

public class BuildingsAtRisk {

//	Declare member variables
	private ArrayList<Point> boundingBox, buildings, buildingsAtRisk;
	
//	Constructor for buildings at risk
	public BuildingsAtRisk (ArrayList<Point> boundingBox, ArrayList<Point> buildings){

		this.boundingBox = boundingBox;
		this.buildings = buildings;
		buildingsAtRisk = new ArrayList<Point>();
		
		Iterator<Point> itrBuildingPoints = buildings.iterator(); 
		
//		System.out.println("");
//		System.out.println("Evaluate whether building points are within disaster bounding box and print updated list buildings at risk.");
//		System.out.println("");
		
		while(itrBuildingPoints.hasNext()) {
						
			Point p = itrBuildingPoints.next();

			if (isInside(boundingBox, p)){			
				buildingsAtRisk.add(p);
//				System.out.println("At risk ... adding to list.");
//				System.out.println(buildingsAtRisk);
			}			
			else {
//				System.out.println("Not at risk.");
			}
		}				
	}


	
//	Method to determine if a building point is inside of bounding box
	public boolean isInside(ArrayList<Point> boundingBox, Point p){

		if(boundingBox.get(0).getX()<boundingBox.get(1).getX()  
		    && boundingBox.get(0).getY()>boundingBox.get(1).getY()
		    && boundingBox.get(0).getX()<p.getX()  
		    && boundingBox.get(1).getX()>p.getX()
		    && boundingBox.get(0).getY()>p.getY()
		    && boundingBox.get(1).getY()<p.getY()){
				return true;
		}
		else{
			return false;
		}
	}
	
	
//	Getters and setters
	
	public ArrayList<Point> getBuildings() {
		return buildings;
	}

	public void setBuildings(ArrayList<Point> buildings) {
		this.buildings = buildings;
	}

	public ArrayList<Point> getBuildingsAtRisk() {
		return buildingsAtRisk;
	}

	public void setBuildingsAtRisk(ArrayList<Point> buildingsAtRisk) {
		this.buildingsAtRisk = buildingsAtRisk;
	}
}

